package com.gigi.controller;

import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.gigi.common.IdRequest;
import com.gigi.model.dto.TeamDTO;
import com.gigi.model.request.JoinTeamRequest;
import com.gigi.model.request.SearchTeamsRequest;
import com.gigi.model.vo.TeamMemberVO;
import com.gigi.model.vo.TeamUserVO;
import com.gigi.service.manual.TeamManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@Api(tags = "队伍管理")
@RestController
@RequestMapping("team-manage")
public class TeamManageController {

    @Autowired
    private TeamManageService teamManageService;

    @ApiOperation(value = "创建队伍")
    @PostMapping("create")
    public Response createTeam(@RequestBody @Valid TeamDTO teamDO, HttpServletRequest httpServletRequest) {
        return teamManageService.createTeam(teamDO, httpServletRequest);
    }

    @ApiOperation(value = "搜索队伍")
    @PostMapping("search")
    public MultiResponse<TeamUserVO> searchTeam(@RequestBody SearchTeamsRequest request, HttpServletRequest httpServletRequest) {
        return teamManageService.searchTeam(request, httpServletRequest);
    }

    @ApiOperation(value = "修改队伍信息")
    @PostMapping("edit")
    public Response editTeam(@RequestBody @Valid TeamDTO teamDO, HttpServletRequest httpServletRequest) {
        return teamManageService.editTeam(teamDO, httpServletRequest);
    }

    @ApiOperation(value = "解散队伍")
    @PostMapping("disband")
    public Response disbandTeam(@RequestBody @Valid IdRequest request, HttpServletRequest httpServletRequest) {
        return teamManageService.disbandTeam(request, httpServletRequest);
    }

    @ApiOperation(value = "加入队伍")
    @PostMapping("join")
    public Response joinTeam(@RequestBody @Valid JoinTeamRequest request, HttpServletRequest httpServletRequest) {
        return teamManageService.joinTeam(request, httpServletRequest);
    }

    @ApiOperation(value = "退出队伍")
    @PostMapping("quit")
    public Response quitTeam(@RequestBody @Valid IdRequest request, HttpServletRequest httpServletRequest) {
        return teamManageService.quitTeam(request, httpServletRequest);
    }

    @ApiOperation(value = "根据id获取队伍")
    @PostMapping("get")
    public SingleResponse<TeamDTO> getTeamById(@RequestBody @Valid IdRequest request, HttpServletRequest httpServletRequest) {
        return teamManageService.getTeamById(request, httpServletRequest);
    }

    @ApiOperation(value = "我的队伍")
    @PostMapping("mine")
    public MultiResponse<TeamUserVO> myTeam(HttpServletRequest httpServletRequest) {
        return teamManageService.myTeam(httpServletRequest);
    }

    @ApiOperation(value = "队员列表")
    @PostMapping("member")
    public SingleResponse<TeamMemberVO> memberList(@RequestBody @Valid IdRequest request, HttpServletRequest httpServletRequest) {
        return teamManageService.memberList(request, httpServletRequest);
    }

}
